There’s no need to null test in conjunction with an instanceof
test. null
is not an instanceof
anything, so
a null check is redundant.
Noncompliant code example
if (x != null && x instanceof MyClass) { ... } // Noncompliant
if (x == null || ! x instanceof MyClass) { ... } // Noncompliant
Compliant solution
if (x instanceof MyClass) { ... }
if (! x instanceof MyClass) { ... }